package com.ziyucoding.springboot.labs.lab8.skywalking.traceannotationsdemo.controller;

import org.apache.skywalking.apm.toolkit.trace.ActiveSpan;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 示例 控制器
 *
 * @author ziyucoding
 * @date 2022-11-01
 **/
@RestController
@RequestMapping("/demo")
public class DemoController {


    @GetMapping("/hello")
    @Trace(operationName = "hello_trace_annotations")
    public Map<String, Object> sayHello() {
        // 自定义 SkyWalking Span
        ActiveSpan.tag("hello", "ziyucoding");

        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("msg", "成功");
        result.put("data", "hello_trace_annotations");
        return result;
    }

}
